package zrar.panel;

import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Observable;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

import zrar.util.SystemUtil;

public class ButtonPanel extends Observable implements ActionTouchImpl{
	
	private JPanel thisPanel = new JPanel();
	
	//private JButton run_but;  
	//private JButton stop_but;
	private JButton ready_but;
	private JButton showResult_but;  //显示结果
	
	private int butNum ;
	private static final int READY=0;
	private static final int RUN=1;
	private static final int STOP=2;
	private static final int SHOW=3;
	
	ImageIcon ready0_icon = SystemUtil.createImageIcon("ready_btn0.png");
	ImageIcon ready1_icon = SystemUtil.createImageIcon("ready_btn1.png");
	
	public ButtonPanel(){
		
		//thisPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		thisPanel.setLayout(null);
		
		
		ImageIcon show_icon = SystemUtil.createImageIcon("list_btn.png");
		
		ready_but = new JButton(ready1_icon);
		showResult_but = new JButton();
		showResult_but.setIcon(show_icon);
		
		init();
				
		thisPanel.add(ready_but);
		thisPanel.add(showResult_but);
		
		
	}
	
	private void init(){
		
		ready_but.setBounds(180,10,135, 40);
		showResult_but.setBounds(350,10,135, 40);
		
		ready_but.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e) {
				//READY
				notifyTheObservers(READY);
			}
		});
		showResult_but.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e) {
				notifyTheObservers(SHOW);
			}
		});
	}
	
	static int ff= 1;
	protected void ready_Action() {
		
		if(ff==1){
			ready_but.setIcon(ready0_icon);
			ff=0;
		}else{
			ready_but.setIcon(ready1_icon);
			ff=1;
		}
	}

	public JPanel getPane(){
		return thisPanel;
	}
	
	private void notifyTheObservers(int flag){		
		setActionNum(flag);
		this.setChanged();
	    this.notifyObservers();
	}

	@Override
	public int getActionNum() {
		return butNum;
	}

	@Override
	public void setActionNum(int actionNum) {
		this.butNum = actionNum;		
	}
	
	
	public void changeReadyBtn(int info) {
		if(info==0){
			ready_but.setIcon(ready0_icon);
		}else if(info==1){
			ready_but.setIcon(ready1_icon);
		}
	}
		
}
